package com.pet.server.ext.action.article;


import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.Article;
import com.pet.server.ext.service.ArticleService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;

public class Detail extends ActionBase{
	public Integer article_id;
	public String wechat="0";
	public Detail(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		article_id = NumberUtil.getInteger(params.getFieldValue("article_id"), 0);
	
		String ua = params.getRequest().getHeader("user-agent");
		if(ua.matches("(?i).*android.*micromessenger.*")){
			wechat="1";
		}
		
		
		
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		ArticleService articleService = new ArticleService();
		Article article = articleService.findArticle(article_id);
		Result result = new Result();
        result.setAttr("article", article);
        result.setAttr("wechat", wechat);
        result.setRedirect("/article/detail.jsp", "forward");
	    return result;
	}


}
